<template>
	<view class="container">
		<view class="user-section">
			<image class="bg" src="https://www.jieqinwang.com/Public/images/mobile/user-bg.png"></image>
			<view class="user-info-box" v-if="hasLogin">
				<view class="portrait-box">
					<image class="portrait" src="https://img.zcool.cn/community/01a3865ab91314a8012062e3c38ff6.png"></image>
				</view>
				<view class="info-box">
					<text class="username">{{ userInfo.username}}</text>
				</view>
			</view>
			<navigator url="../login/login" hover-class="none" class="user-info-box" v-else>
				<view class="portrait-box">
					<image class="portrait" src="https://img.zcool.cn/community/01a3865ab91314a8012062e3c38ff6.png"></image>
				</view>
				<view class="info-box">
					<text class="username">去登录</text>
				</view>
			</navigator>
		</view>

		<view class="cover-container" :style="[
				{
					transform: coverTransform,
					transition: coverTransition
				}
			]"
		 @touchstart="coverTouchstart" @touchmove="coverTouchmove" @touchend="coverTouchend">

			<view class="tj-sction">
				<view class="tj-item" @click="toOrder()">
					<text class="iconfont icon-yufukuan"></text>
					<text>预约单</text>
				</view>
				<view class="tj-item" @click="toOrder()">
					<text class="iconfont icon-daifukuan"></text>
					<text>支付单</text>
				</view>
				<view class="tj-item" @click="toOrder()">
					<text class="iconfont icon-quanbudingdan"></text>
					<text>我的订单</text>
				</view>
				<view class="tj-item">
					<text class="iconfont icon-shoucang"></text>
					<text>收藏</text>
				</view>
			</view>
			<view class="history-section icon">
				<list-cell icon="icon-gongju" iconColor="#e07472" title="结婚工具" ></list-cell>
				<list-cell icon="icon-bangzhu" iconColor="#5fcda2" title="帮助中心" @eventClick="navTo('/pages/user/help_center')"></list-cell>
				<list-cell icon="icon-dianhuazixunhuawuzongheguanlibl" iconColor="#9789f7" title="客服电话" @eventClick="onTel"></list-cell>
				<list-cell icon="icon-jiamengshangjiage" iconColor="#ee883b" title="城市加盟"></list-cell>
				<list-cell icon="icon-chezhu" iconColor="#54b4ef" title="成为车主" tips="邀请好友赢10万大礼"></list-cell>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';
	import listCell from '@/components/mix-list-cell';
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	export default {
		components: {
			listCell
		},
		data() {
			return {
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false
			};
		},
		onShow() {
			console.log(this.hasLogin)
		},
		onLoad() {
			
		},
		computed:{
			...mapState(['hasLogin']),
			...mapState(['userInfo'])
		},
		methods: {
			//跳转订单
			toOrder(){
				uni.switchTab({
					url: '../order/order_list'
				})
			},
			/**
			 * 统一跳转接口
			 */
			navTo(url) {
				uni.navigateTo({
					url
				});
			},
			/**
			 * 客服电话
			 */
			onTel() {
				uni.makePhoneCall({
					phoneNumber: '17600200576'
				});
			},
			/**
			 *  会员卡下拉和回弹
			 *  1.关闭bounce避免ios端下拉冲突
			 *  2.由于touchmove事件的缺陷（以前做小程序就遇到，比如20跳到40，h5反而好很多），下拉的时候会有掉帧的感觉
			 *    transition设置0.1秒延迟，让css来过渡这段空窗期
			 *  3.回弹效果可修改曲线值来调整效果，推荐一个好用的bezier生成工具 http://cubic-bezier.com/
			 */
			coverTouchstart(e) {
				if (pageAtTop === false) {
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e) {
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if (moveDistance < 0) {
					this.moving = false;
					return;
				}
				this.moving = true;
				if (moveDistance >= 80 && moveDistance < 100) {
					moveDistance = 80;
				}

				if (moveDistance > 0 && moveDistance <= 80) {
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend() {
				if (this.moving === false) {
					return;
				}
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			}
		}
	};
</script>
<style lang="scss">
	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%section {
		display: flex;
		justify-content: space-around;
		align-content: center;
		background: #fff;
		border-radius: 10upx;
	}

	.user-section {
		height: 520upx;
		padding: 100upx 30upx 0;
		position: relative;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			filter: blur(1px);
			opacity: 0.7;
		}
	}

	.user-info-box {
		height: 180upx;
		display: flex;
		align-items: center;
		position: relative;
		z-index: 1;

		.portrait {
			width: 130upx;
			height: 130upx;
			border: 5upx solid #fff;
			border-radius: 50%;
		}

		.username {
			font-size: $font-lg + 6upx;
			color: $font-color-dark;
			margin-left: 20upx;
		}
	}

	.cover-container {
		margin-top: -80upx;
		padding: 0 30upx;
		position: relative;
		padding-bottom: 20upx;

		.arc {
			position: absolute;
			left: 0;
			top: -34upx;
			width: 100%;
			height: 36upx;
		}
	}

	.tj-sction {
		@extend %section;
		box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.1);

		.tj-item {
			@extend %flex-center;
			flex-direction: column;
			height: 140upx;
			font-size: $font-sm;
			color: #75787d;

			.iconfont {
				font-size: 48upx;
			}
		}

		.num {
			font-size: $font-lg;
			color: $font-color-dark;
			margin-bottom: 8upx;
		}
	}

	.order-section {
		@extend %section;
		padding: 28upx 0;
		margin-top: 20upx;

		.order-item {
			@extend %flex-center;
			width: 120upx;
			height: 120upx;
			border-radius: 10upx;
			font-size: $font-sm;
			color: $font-color-dark;

		}

		.yticon {
			font-size: 48upx;
			margin-bottom: 18upx;
			color: #fa436a;
		}

		.icon-shouhoutuikuan {
			font-size: 44upx;
		}
	}

	.history-section {
		margin-top: 40upx;
		background: #fff;
		box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.1);
		border-radius: 10upx;

		.sec-header {
			display: flex;
			align-items: center;
			font-size: $font-base;
			color: $font-color-dark;
			line-height: 40upx;
			margin-left: 30upx;

			.yticon {
				font-size: 44upx;
				color: #5eba8f;
				margin-right: 16upx;
				line-height: 40upx;
			}
		}

		.h-list {
			white-space: nowrap;
			padding: 30upx 30upx 0;

			image {
				display: inline-block;
				width: 160upx;
				height: 160upx;
				margin-right: 20upx;
				border-radius: 10upx;
			}
		}
	}
</style>
